﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Text;
using BML.Infrastructure;
using BML.Infrastructure.Implement;
using Model.BusinessLogic.PhysicalData;
using Service.Infrastructure;
using Service.Infrastructure.Interface;
using Service.Infrastructure.Model;
using Service.Infrastructure.Result;
using Service.Work.Model;
using SystmicFunction.Public.CacheService;


namespace Service.Infrastructure.Implement
{
    /// <summary>
    ///     用户操作
    /// </summary>
    public class MemberService : BaseService, IAccount
    {


        /// <summary>
        ///     常见类型：
        ///     1.用户名（帐号、手机号、邮箱）、密码
        ///     2.用户名、密码、验证码
        /// </summary>
        /// <param name="userKey"></param>
        /// <param name="param">参数顺序：</param>
        /// <returns></returns>
        public ServiceResult Login(string userKey, params object[] param)
        {
            if (ParamsIsNull(userKey, param[0]))
                return Result(ResultType.ParmamIsNull);

            var process = new WorkProcess(this, Result(ResultType.Error));
            Expression<Func<WebAccount, bool>> predicate = m => m.Account == (string)param[0];

            

            //之所以分开：是因为每一“步”都需要验证，如不需要验证，应该在BML聚合为一个方法
            return process.DoProcess(new Dictionary<String, Object[]>{
                                        {"BaseOperator-ReadSingle", new object[] {predicate}},
                                        {"WebAccountOp-Create", new[] {param[0], param[1]}}
                                    },
                                    ResultType.AccountLoginSuccess,
                                    typeof(UserModel), new Dictionary<string, string>{
                                        {"Name","WebAccount-account"},//Viewmodel-Prop,Model-Prop
                                        {"CreateTime","WebAccount-CreateTime"}
                                    }
                                    );
        }

        /// <summary>
        ///     常见类型：
        ///     1.用户名、密码
        ///     2.用户名、密码、验证码
        /// </summary>
        /// <param name="userKey"></param>
        /// <param name="info"></param>
        /// <returns></returns>
        /// AOP,DI,IOC
        public ServiceResult Reg(string userKey, params object[] info)
        {
            if (ParamsIsNull(info[0], info[1]))
                return Result(ResultType.ParmamIsNull);

            return Result(ResultType.AccountRegisterIsSuccess);
        }

        public ServiceResult KeepSession(String sessionKey,params object[] info)
        {
            throw new NotImplementedException();
        }

        /// <summary>
        ///     查询与用户相关联的所有用户
        /// </summary>
        /// <returns></returns>
        public ServiceResult QueryUsers()
        {
            throw new NotImplementedException();
        }



    }
}
